using System;
using System.Collections.Generic;
using Itdavany;
using Itdavany.Utility;
using Itdavany.Data;
using RollingKitty.Data;
using RollingKitty.Stages;
using RollingKitty.Objects;

namespace RollingKitty.Stages
{
    public class GameOverStage : KittyStage
    {
        Button btn_yes, btn_no;

        StageClosedEventArgs arg;
        FrameArray frms;

        GameObjectGroup overlayer = new GameObjectGroup();

        public GameOverStage()
        {
            /*CurrentScene = new Scene();
            GameObjectGroup layer = new GameObjectGroup();
            SkinData bk_skin = (SkinData)Shared.GlobalBackstageGroup["skin"];

            //btn_yes = new Button();
            layer.Add("back", new TexturedPane(@"Content\GameOver\Gameoverback"));
            layer.Add("back2", new TexturedPane(@"Content\GameOver\overmessage", 180, 200));

            btn_yes = new Button(bk_skin.Button["btn_overyes"]);
            btn_yes.X = 190; btn_yes.Y = 300;
            btn_yes.LeftClicked += new EventHandler(OnYes);
            layer.Add("btn_yes", btn_yes);

            //btn_no = new Button();
            btn_no = new Button(bk_skin.Button["btn_overno"]);
            btn_no.X = 450; btn_no.Y = 300;
            btn_no.LeftClicked += new EventHandler(OnNo);
            layer.Add("btn_no", btn_no);

            layer.Add("cursor", new MouseCursor(bk_skin.MouseCursor["cursor_default"]));


            Configuration conf = (Configuration)Shared.GlobalBackstageGroup["conf"];

            FaderObject = new ScreenFader(conf.programConfig.screenFader.texture);
            FaderObject.FadeSpeed = conf.programConfig.screenFader.fadespeed;
            FaderObject.FadeOutOver += new EventHandler(OnFadeOutOver);
            layer.Add("fader", FaderObject);


            CurrentScene.Add(layer);*/

            frms = Shared.ObjectDescriber.GetObject<FrameArray>(@"Content\Stage\GameOver");

            btn_yes = (Button)frms.FindObject("btn_yes");
            btn_yes.LeftClicked += new EventHandler(OnYes);

            btn_no = (Button)frms.FindObject("btn_no");
            btn_no.LeftClicked += new EventHandler(OnNo);

            overlayer.Add("cursor", new MouseCursor());

            Configuration conf = (Configuration)Shared.GlobalBackstageGroup["conf"];
            FaderObject = new ScreenFader(conf.programConfig.screenFader.texture);
            FaderObject.FadeSpeed = conf.programConfig.screenFader.fadespeed;
            FaderObject.FadeOutOver += new EventHandler(OnFadeOutOver);
            overlayer.Add("fader", FaderObject);


            CurrentScene = new List<Scene>(frms.Values)[0];
            CurrentScene.Add(overlayer);


            arg = new StageClosedEventArgs();

            FadeInAndFreeze();
        }

        protected void OnFadeOutOver(object obj, EventArgs e)
        {
            RaiseClosed(arg);
        }

        protected void OnYes(object obj, EventArgs e)
        {
            arg.code = "mainmenu";
            FadeOutAndFreeze();
        }

        protected void OnNo(object obj, EventArgs e)
        {
            arg.code = "exit";
            FadeOutAndFreeze();
        }
    }
}